package net.siufung.market.base.tenant.controller.regulation;

import lombok.AllArgsConstructor;
import net.siufung.core.exception.BizServiceException;
import net.siufung.core.model.enums.InitializeEnum;
import net.siufung.core.model.regulation.AbstractRegulation;
import net.siufung.market.base.tenant.mapper.ITenantMapper;
import net.siufung.market.base.tenant.mapper.entity.Tenant;

import java.util.Objects;

/**
 * @author 陈建峰
 * @since 2022/6/24 3:21 下午
 */
@AllArgsConstructor
public class TenantDeleteRegulation extends AbstractRegulation<Integer> {

    private static final long serialVersionUID = 5828207773203786860L;

    private final ITenantMapper tenantMapper;

    @Override
    public boolean isSatisfiedBy(Integer tenantId) {
        if(Objects.isNull(tenantId)){
            throw new BizServiceException("主键不能为空！");
        }
        Tenant tenant = tenantMapper.selectById(tenantId);
        if(Objects.isNull(tenant)){
            throw new BizServiceException("租户不存在！");
        }
        if(InitializeEnum.IS.getValue().equals(tenant.getTenantInitState())){
            throw new BizServiceException("租户已激活，不允许删除!");
        }
        return Boolean.TRUE;
    }
}
